package com.mutual.assistance.user.mq.config;

import com.mutual.assistance.user.constant.MqConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author chenyuxin
 * @version 1.0
 * @description RabbitMq配置
 * @date 2023/4/29 21:19
 */
@Configuration
public class RabbitMqConfig {

    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(MqConstant.USER_EXCHANGE);
    }

    @Bean
    public Queue fanoutQueue() {
        return new Queue(MqConstant.USER_QUEUE);
    }

    @Bean
    public Binding fanoutBind(FanoutExchange fanoutExchange, Queue fanoutQueue) {
        return BindingBuilder
                .bind(fanoutQueue)
                .to(fanoutExchange);
    }


    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }

}
